$(function () {





    //左侧菜单 元素收起
    $(".main-item-left .away-perhaps-away-warp").click(function () {
        const itenClass = $(".main-item-left").attr("class").indexOf("active")
        if (itenClass === -1) {
            $(".main-item-left").attr("class", "main-item-left active")
            $(this).text("点击收起")
        } else {
            $(".main-item-left").attr("class", "main-item-left")
            $(this).text("点击展开")
        }
    })
    //右边元素收起
    $(".main-item-right .away-perhaps-away-warp").click(function () {
        const itenClass = $(".main-item-right").attr("class").indexOf("active")
        if (itenClass === -1) {
            $(".main-item-right").attr("class", "main-item-right active")
            $(this).text("点击收起")
        } else {
            $(".main-item-right").attr("class", "main-item-right")
            $(this).text("点击展开")
        }
    })

    //左侧菜单 顶部切换事件
    $(".left-header span").click(function () {
        const index = $(this).index()
        const header_p_width = $(this).innerWidth() - 46
        $(".left-header p").css({ width: header_p_width, left: $(this).offset().left + 22 })

        $(this).addClass("active").siblings("span").removeClass("active")
        if (index === 0) {
            $(".menu-main").show()
            $(".sousuo-main").hide()
        } else {
            $(".sousuo-main").show()
            $(".menu-main").hide()
        }
    })



    let data = [{
        "title": "科学家精神",
        "id": 1,
        "children": [{
            "title": "酒香飘世界，虽醉亦风流",
            "id": 1000,
            "children": [{
                "title": "李贵真：唯精唯一做蚤类研究",
                "id": 10001
            }, {
                "title": "“新冠病毒”的当下治与防",
                "id": 10002
            }]
        }, {
            "title": "关于消毒液你应知道的事儿",
            "id": 1001
        }, {
            "title": "复工复产时，防控这样做",
            "id": 1002
        }]
    }, {
        "title": "科学视点",
        "id": 2,
        "children": [{
            "title": "这份“心理处方”请收好",
            "id": 2000
        }, {
            "title": "疫苗从出现到入市为何那么“漫长”",
            "id": 2001
        }]
    }]

    ZUI.tree({
        data: data,
        title: 'title',
        id: 'id',
        elem: '#test2',
        children: 'children',
        iconfont: 'iconfont|icon-add_circle|icon-iconset0187|icon-file',
        callBack: function (con) {
            console.log(con);
        }
    })




    // const funTypeInfo = {
    //     "1": { name: "上一篇" },
    //     "2": { name: "下一篇" },
    //     "3": { name: "放大" },
    //     "4": { name: "缩小" },
    //     "5": { name: "左旋" },
    //     "6": { name: "右旋" },
    //     "7": { name: "打印" },
    // }
    let rotateNum = 0
    let scaleNum = 1

    $(".hint--bottom").click(function (e) {
        // console.log(e.currentTarget.dataset)
        const { type } = e.currentTarget.dataset
        if (type === "1") {

        } else if (type === "2") {

        } else if (type === "3") {//放大
            scaleNum = scaleNum + 0.1
            if (scaleNum > 2) {
                return
            }
            setMainImgWarp(rotateNum, scaleNum)
        } else if (type === "4") {//缩小
            scaleNum = scaleNum - 0.1
            if (scaleNum <= 0.3) {
                return
            }
            setMainImgWarp(rotateNum, scaleNum)
        } else if (type === "5") {//左旋 
            rotateNum = rotateNum - 90
            setMainImgWarp(rotateNum, scaleNum)
        } else if (type === "6") {//右旋
            rotateNum = rotateNum + 90
            setMainImgWarp(rotateNum, scaleNum)
        } else if ( type === "7" ){
            sessionStorage.setItem("startprint",$(".img-warp img").attr("src"))
            window.open("./startprint.html");
        }
    })
    //设置图片功能样式
    function setMainImgWarp(rotate, scale) {
        $(".main-item-center .img-warp").css({
            "transform": `rotate(${rotate}deg) scale(${scale})`
        })
    }




    const imgArr = ['./images/test-img/1.jpg', './images/test-img/2.jpg', './images/test-img/3.jpg']

    //上一页
    $(".btn-left-click").click(function () {
        let res = imgArr[Math.ceil(Math.random() * 2)] //模拟请求成功后 得到的图片路径 
        $(".loading-warp").show()
        setTimeout(() => {
            $(".loading-warp").hide()
            $(".img-warp img").attr("src", res)
        }, 2000)
    })
    //下一页
    $(".btn-right-click").click(function () {
        let res = imgArr[Math.ceil(Math.random() * 2)] //模拟请求成功后 得到的图片路径
        $(".img-warp img").attr("src", res)
    })





    


    










})